package com.minelx.datamicroscope.core.index;

import com.minelx.datamicroscope.core.condition.RawCondition;
import com.minelx.datamicroscope.core.query.AliasedKey;
import com.minelx.datamicroscope.core.query.CollectingResource;
import com.minelx.hellopandas.core.PandasMethodProvider;
import io.gitee.minelx.filesystem.Directory;
import io.gitee.minelx.filesystem.File;

import java.util.List;

class StoredDataFrameDirectoryConditionalIndexFactory implements ConditionalIndexFactory {

	private final PandasMethodProvider pandasMethodProvider;

	private final Directory storedDirectory;

	StoredDataFrameDirectoryConditionalIndexFactory(PandasMethodProvider pandasMethodProvider, Directory storedDirectory) {
		this.pandasMethodProvider = pandasMethodProvider;
		this.storedDirectory = storedDirectory;
	}

	@Override
	public boolean available(String repositoryTablePath) {
		return storedDirectory.child().path(repositoryTablePath).exists();
	}

	@Override
	public Index createIndex(List<AliasedKey> remainingKeys, List<RawCondition> conditions, CollectingResource collectingResource, File destination) {
		return new FileIndex(pandasMethodProvider, storedDirectory, remainingKeys, conditions, collectingResource, destination);
	}
}
